home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 1.toast / pc / sample code / contributed / waste / demo / source / wedemointf.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  9.9 KB  |  443 lines

  1. /*
  2.     WASTE Demo Project:
  3.     Demo Header
  4.  
  5.     Copyright © 1993-1998 Marco Piovanelli
  6.     All Rights Reserved
  7.  
  8.     C port by John C. Daub
  9. */
  10.  
  11. /*
  12.     Due to differences between Pascal and C, this file (nothing like it originally existed
  13.     in the original Pascal code) was neccessary to create.  In it contains various macros,
  14.     constants, type and class declarations, function prototypes, etc..  From the original
  15.     code, some of this material would be spread amongst the source files, but a good
  16.     majority of this file comes from the WEDemoIntf.p file (the declarations, constants, etc).
  17.     There still is a WEDemoIntf.c file in the project tho since the .p file had a few
  18.     utility functions declared and defined in it.
  19. */
  20.  
  21. #ifndef __WEDEMOAPP__
  22. #define __WEDEMOAPP__
  23.  
  24. #ifndef __TYPES__
  25. #include <Types.h>
  26. #endif
  27.  
  28. #ifndef __RESOURCES__
  29. #include <Resources.h>
  30. #endif
  31.  
  32. #ifndef __QUICKDRAW__
  33. #include <QuickDraw.h>
  34. #endif
  35.  
  36. #ifndef __MENUS__
  37. #include <Menus.h>
  38. #endif
  39.  
  40. #ifndef __WINDOWS__
  41. #include <Windows.h>
  42. #endif
  43.  
  44. #ifndef __CONTROLS__
  45. #include <Controls.h>
  46. #endif
  47.  
  48. #ifndef __STANDARDFILE__
  49. #include <StandardFile.h>
  50. #endif
  51.  
  52. #ifndef _WASTE_
  53. #include "WASTE.h"
  54. #endif
  55.  
  56. #ifndef _LIMITS
  57. #include "limits.h"
  58. #endif
  59.  
  60.  
  61. /*
  62.  *    Some utility macros.
  63.  */
  64.  
  65.  
  66.  
  67. //     "Originally," these are things built into the Pascal language
  68. //     but since C doesn't have anything like them, and in an attempt to keep the code readable
  69. //     and similar to the original Pascal source, these #define macros work nice.
  70.  
  71.  
  72. #define BTST( FLAGS, BIT )                ((FLAGS) &   (1UL << (BIT)))
  73. #define BSET( FLAGS, BIT )              ((FLAGS) |=  (1UL << (BIT)))
  74. #define BCLR( FLAGS, BIT )              ((FLAGS) &= ~(1UL << (BIT)))
  75. #define BCHG( FLAGS, BIT )              ((FLAGS) ^=  (1UL << (BIT)))
  76.  
  77. #define ABS(A) ((A) > 0 ? (A) : -(A))
  78.  
  79. #define BSL(A, B)    (((long) (A)) << (B))
  80. #define BSR(A, B)    (((long) (A)) >> (B))
  81. #define BOR(A, B)    ((A) | (B))
  82. #define BAND(A, B)    ((A) & (B))
  83.  
  84. #ifndef HiWrd
  85. #define HiWrd(aLong)        (((aLong) >> 16) & 0xFFFF )
  86. #endif
  87. #ifndef LoWrd
  88. #define LoWrd(aLong)        ((aLong) & 0xFFFF )
  89. #endif
  90.  
  91. enum {
  92.  
  93. //    WASTE Demo signature
  94.  
  95.     sigWASTEDemo        =        'OEDE',
  96.  
  97. //    resource types, clipboard types, and file types
  98.  
  99.     kTypeDeskAccessory    =        'DRVR',
  100.     kTypeFont            =        'FONT',
  101.     kTypeFontTable        =        'FISH',
  102.     kTypePicture        =        'PICT',
  103.     kTypeSound            =        'snd ',
  104.     kTypeSoup            =        'SOUP',
  105.     kTypeStyles            =        'styl',
  106.     kTypeText            =        'TEXT'
  107. };
  108.  
  109. enum {
  110.  
  111. //    virtual key codes for navigation keys found on extended keyboards
  112.  
  113.     keyPgUp                =        0x74,
  114.     keyPgDn                =        0x79,
  115.     keyHome                =        0x73,
  116.     keyEnd                =        0x77,
  117.  
  118. //    virtual key codes generated by some function keys
  119.  
  120.     keyF1                =        0x7A,
  121.     keyF2                =        0x78,
  122.     keyF3                =        0x63,
  123.     keyF4                =        0x76
  124. };
  125.  
  126. //    possible values for HandleOpenDocument refCon parameter
  127.  
  128. enum {
  129.     kDoOpen        = 0,
  130.     kDoPrint    = 1
  131. };
  132.  
  133. //     other commonly used constants
  134.  
  135. #define    kBarWidth                        16            // width of a scroll bar
  136. #define kTitleHeight                    20            // usual height of a window title bar
  137. #define kTextMargin                        3            // indent of text rect from a window port rect
  138. #define kScrollDelta                    11            // pixels to scroll when the scroll bar arrow is clicked
  139. #define kStandardTranslucencyThreshold    16384        // 16K sq pixels
  140.  
  141. #define kMinSystemVersion                0x0700        //    MacOS 7.0
  142. #define kMinWASTEVersion                0x01308000    //    WASTE 1.3f
  143. #define kScrapThreshold                    4 * 1024    //    4 KB
  144.  
  145. // enumeration types used for closing a window and/or quitting the application
  146.  
  147. typedef enum {closingWindow, closingApplication} ClosingOption;
  148. typedef enum {savingYes, savingNo, savingAsk} SavingOption;
  149.  
  150. // enumeration for orientation (vertical/horizontal)
  151.  
  152. typedef enum {kVertical, kHorizontal} Orientation;
  153.  
  154. /*
  155.  *    Resource ID numbers
  156.  */
  157.  
  158. // menu IDs
  159.  
  160. enum {
  161.     kMenuApple        = 1,
  162.     kMenuFile,
  163.     kMenuEdit,
  164.     kMenuFont,
  165.     kMenuSize,
  166.     kMenuStyle,
  167.     kMenuColor,
  168.     kMenuFeatures,
  169.     kMenuAlignment,
  170.     kMenuDirection
  171. };
  172.  
  173. //    Apple Menu items
  174.  
  175. enum {
  176.     kItemAbout        = 1
  177. };
  178.  
  179. //    File menu items
  180.  
  181. enum {
  182.     kItemNew        = 1,
  183.     kItemOpen        = 2,
  184.     kItemClose        = 4,
  185.     kItemSave        = 5,
  186.     kItemSaveAs        = 6,
  187.     kItemQuit        = 8
  188. };
  189.  
  190. //    Edit menu items
  191.  
  192. enum {
  193.     kItemUndo        = 1,
  194.     kItemCut        = 3,
  195.     kItemCopy        = 4,
  196.     kItemPaste        = 5,
  197.     kItemClear        = 6,
  198.     kItemSelectAll    = 7
  199. };
  200.  
  201. //    Size menu items
  202.  
  203. enum {
  204.     kItemLastSize    = 6,
  205.     kItemSmaller    = 8,
  206.     kItemLarger        = 9,
  207.     kItemOtherSize    = 11
  208. };
  209.  
  210. //    Style menu items
  211.  
  212. enum {
  213.     kItemPlainText    = 1,
  214.     kItemBold,
  215.     kItemItalic,
  216.     kItemUnderline,
  217.     kItemOutline,
  218.     kItemShadow,
  219.     kItemCondensed,
  220.     kItemExtended
  221. };
  222.  
  223. //    Color menu items
  224.  
  225. enum {
  226.     kItemLastColor    = 7,
  227.     kItemOtherColor = 9
  228. };
  229.  
  230. //    Alignment menu items
  231.  
  232. enum {
  233.     kItemAlignDefault    = 1,
  234.     kItemAlignLeft        = 3,
  235.     kItemCenter,
  236.     kItemAlignRight,
  237.     kItemJustify
  238. };
  239.  
  240. //    Direction menu items
  241.  
  242. enum
  243. {
  244.     kItemDirectionDefault = 1 ,
  245.     kItemDirectionLR = 3 ,
  246.     kItemDirectionRL
  247. } ;
  248.  
  249. //    Features menu items
  250.  
  251. enum {
  252.     kItemAlignment            = 1,
  253.     kItemDirection            = 2,
  254.     kItemTabHooks            = 3,
  255.     kItemAutoScroll            = 5,
  256.     kItemOutlineHilite        = 6,
  257.     kItemReadOnly            = 7,
  258.     kItemIntCutAndPaste     = 8,
  259.     kItemDragAndDrop        = 9,
  260.     kItemTranslucentDrags    = 10,
  261.     kItemOffscreenDrawing    = 11
  262. };
  263.  
  264.  
  265. //    Alert & dialog template resource IDs
  266.  
  267. enum {
  268.     kAlertNeedSys7            = 128,
  269.     kAlertNeedNewerWASTE    = 129,
  270.     kAlertGenError            = 130,
  271.     kAlertSaveChanges        = 131,
  272.     kDialogAboutBox            = 256
  273. };
  274.  
  275. //    String list resource IDs
  276.  
  277. enum {
  278.     kUndoStringsID                = 128,
  279.     kClosingQuittingStringsID    = 129,
  280.     kMiscStringsID                = 130
  281. };
  282.  
  283. // miscellaneous resource IDs
  284.  
  285. enum {
  286.     kMenuBarID                = 128,
  287.     kWindowTemplateID        = 128,
  288.     kScrollBarTemplateID    = 128,
  289.     kPromptStringID            = 128
  290. };
  291.  
  292. // a DocumentRecord is a structure associated with each window
  293. // a handle to this structure is kept in the window refCon
  294.  
  295. struct DocumentRecord
  296. {
  297.     WindowPtr            owner;                // the window
  298.     ControlHandle        scrollBars [ 2 ];    // its scroll bars
  299.     WEReference         we;                    // its WASTE instance
  300.     Handle                 fileAlias;            // alias to associated file
  301. };  // DocumentRec
  302.  
  303. typedef struct DocumentRecord DocumentRecord, *DocumentPtr, **DocumentHandle;
  304.  
  305.  
  306. /*
  307.  *    The external declaration of some global variables.
  308.  */
  309.  
  310. //  These are defined in WEDemoIntf.c
  311.  
  312. extern    Boolean        gHasColorQD;        // true if Color QuickDraw is available
  313. extern    Boolean        gHasDragAndDrop;    // true if Drag Manager is available
  314. extern    Boolean        gHasTextServices;    // true is the Text Services Manager is available
  315. extern    Boolean        gExiting;            // set this variable to drop out of the event loop and quit
  316.  
  317. /*
  318.  *    Function Prototypes
  319.  */
  320.  
  321. //    From DialogUtils.c
  322.  
  323. ModalFilterUPP    GetMyStandardDialogFilter( void );
  324. short            GetDialogItemType( DialogPtr, short );
  325. Handle            GetDialogItemHandle( DialogPtr, short );
  326. void            GetDialogItemRect( DialogPtr, short, Rect * );
  327. void            SetDialogItemProc( DialogPtr, short, UserItemUPP );
  328. void            FlashButton( DialogPtr, short );
  329.  
  330. //    From LongControls.c
  331.  
  332. OSErr            LCAttach( ControlHandle );
  333. void            LCDetach( ControlHandle );
  334. void            LCSetValue( ControlHandle, long );
  335. void            LCSetMin( ControlHandle, long );
  336. void            LCSetMax( ControlHandle, long );
  337. long            LCGetValue( ControlHandle );
  338. long            LCGetMin( ControlHandle );
  339. long            LCGetMax( ControlHandle );
  340. void            LCSynch( ControlHandle );
  341.  
  342.  
  343. //    From WEDemoIntf.c
  344.  
  345. DocumentHandle    GetWindowDocument(WindowPtr);
  346. #if __cplusplus
  347. inline WEReference GetWindowWE(WindowPtr window) { return (* GetWindowDocument(window))->we; }
  348. #else
  349. #define GetWindowWE(window) (* GetWindowDocument(window))->we
  350. #endif
  351. void            ErrorAlert( OSErr );
  352. void            ForgetHandle( Handle * );
  353. void            ForgetResource( Handle * );
  354. void            BlockClr ( void *, Size ) ;
  355. OSErr            NewHandleTemp( Size, Handle * );
  356. void            PStringCopy( ConstStr255Param, Str255 );
  357.  
  358. //    From WEDemoAbout.c
  359.  
  360. OSErr            WETextBox( short, const Rect *, WEAlignment );
  361. void            DoAboutBox( short );
  362.  
  363. //    From WEDemoDrags.c
  364.  
  365. OSErr            InstallDragHandlers( void );
  366. OSErr            RemoveDragHandlers( void );
  367.  
  368. //    From WEDemoEvents.c
  369.  
  370. void            AdjustCursor( Point, RgnHandle );
  371. void            DoMouseDown( const EventRecord * );
  372. void            DoKeyDown( const EventRecord * );
  373. void            DoDiskEvent( const EventRecord * );
  374. void            DoOSEvent( const EventRecord * );
  375. void            DoHighLevelEvent( const EventRecord * );
  376. void            DoNullEvent( const EventRecord * );
  377. void            DoWindowEvent( const EventRecord *);
  378. void            ProcessEvent( void );
  379. OSErr            GotRequiredParams( const AppleEvent * );
  380. OSErr            InitializeEvents( void );
  381.  
  382. // from WEDemoFiles.c
  383.  
  384. OSErr            ReadTextFile( const FSSpec *, WEReference );
  385. OSErr            WriteTextFile( const FSSpec *, WEReference );
  386. pascal OSErr    TranslateDrag( DragReference, ItemReference, FlavorType, Handle );
  387. pascal OSErr    CheckObjectLock( short, long, StringPtr );
  388. pascal OSErr    FSpCheckObjectLock( const FSSpec * );
  389.  
  390. // from WEDemoInit.c
  391.  
  392. OSErr            Initialize( void );
  393. void            Finalize( void );
  394.  
  395. // from WEDemoMenus.c
  396.  
  397. void            SetDefaultDirectory( const FSSpec * );
  398. short            FindMenuItemText( MenuHandle, ConstStr255Param );
  399. Boolean            EqualColor( const RGBColor *, const RGBColor * );
  400. void            PrepareMenus( void );
  401. void            DoDeskAcc( short );
  402. OSErr            DoNew( void );
  403. OSErr            DoOpen( void );
  404. OSErr            SaveWindow( const FSSpec *, WindowPtr );
  405. OSErr            DoSaveAs( const FSSpec *, WindowPtr );
  406. OSErr            DoSave( WindowPtr );
  407. OSErr            DoClose( ClosingOption, SavingOption, WindowPtr );
  408. OSErr            DoQuit( SavingOption );
  409. void            DoAppleChoice( short );
  410. void            DoFileChoice( short );
  411. void            DoEditChoice( short );
  412. void            DoFontChoice( short, EventModifiers );
  413. void            DoSizeChoice( short );
  414. void            DoStyleChoice( short );
  415. void            DoColorChoice( short );
  416. void            DoAlignmentChoice( short );
  417. void            DoDirectionChoice ( short ) ;
  418. void            DoFeatureChoice( short );
  419. void            DoMenuChoice( long, EventModifiers );
  420. OSErr            InitializeMenus( void );
  421.  
  422. // from WEDemoScripting.c
  423.  
  424. OSErr            WEGetContentsDesc( long, long, Boolean, AEDesc *, WEReference );
  425. OSErr            WESetContentsDesc( long, long, const AEDesc *, WEReference );
  426. OSErr            InstallCoreHandlers( void );
  427.  
  428. // from WEDemoWindows.c
  429.  
  430. void            DoDrag( Point, WindowPtr );
  431. void            DoGrow( Point, WindowPtr );
  432. void            DoZoom( short, WindowPtr );
  433. Boolean            DoContent( Point, const EventRecord *, WindowPtr );
  434. void            DoKey( short, const EventRecord * );
  435. void            DoUpdate( WindowPtr );
  436. void            DoActivate( Boolean, WindowPtr );
  437. OSErr            CreateWindow( const FSSpec * );
  438. void            DestroyWindow( WindowPtr );
  439. void            Resize( Point, WindowPtr );
  440.  
  441.  
  442. #endif /* __WEDEMOAPP__ */
  443.